// 爆炸效果类
export default class Explosion {
  constructor(x, y, enemyType = 'small') {
    this.x = x
    this.y = y

    // 根据敌机类型设置爆炸效果
    switch (enemyType) {
      case 'small':
        this.radius = 20
        this.color = '#ff9900'
        this.life = 15
        break
      case 'medium':
        this.radius = 35
        this.color = '#ff6600'
        this.life = 20
        break
      case 'large':
        this.radius = 50
        this.color = '#ff3300'
        this.life = 30
        break
      default:
        this.radius = 30
        this.color = '#ff9900'
        this.life = 20
    }

    this.maxLife = this.life
  }

  update() {
    this.life--
  }

  render(ctx) {
    const alpha = this.life / this.maxLife
    ctx.globalAlpha = alpha
    ctx.fillStyle = this.color
    ctx.beginPath()
    ctx.arc(this.x, this.y, this.radius * (1 - alpha), 0, Math.PI * 2)
    ctx.fill()
    ctx.globalAlpha = 1
  }

  isFinished() {
    return this.life <= 0
  }
}
